﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KuPeiXun.Utility
{
    /// ===============================================================
    /// 作者：邹学良 
    /// 时间：2013-03-21
    /// 描述：创建
    /// 历史：无
    /// ===============================================================
    public class FactoryManager
    {
        #region 工厂反射实例
        /// <summary>
        /// 工厂反射实例
        /// </summary>
        /// <param name="classPath">命名空间路径</param>
        /// <param name="className">类名</param>
        /// <returns></returns>
        /// ===============================================================
        /// 作者：邹学良 
        /// 时间：2013-03-21
        /// 描述：创建
        /// 历史：无
        /// ===============================================================
        public static object GenerateInstance(string classPath, string className)
        {
            try
            {
                object obj = null;

                System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(classPath);
                if (assembly != null)
                {
                    obj = assembly.CreateInstance(className);
                }
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 工厂反射实例
        /// </summary>
        /// <param name="classPath">命名空间路径</param>
        /// <param name="className">类名</param>
        /// <param name="parameters">构造函数参数数组</param>
        /// <returns></returns>
        /// ===============================================================
        /// 作者：邹学良 
        /// 时间：2013-03-21
        /// 描述：创建
        /// 历史：无
        /// ===============================================================
        public static object GenerateInstance(string classPath, string className,object[] parameters)
        {
            try
            {
                object obj = null;

                System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(classPath);
                if (assembly != null)
                {
                    obj = assembly.CreateInstance(className,false, System.Reflection.BindingFlags.CreateInstance,null,parameters,null,null);
                }
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
